package com.i.template.config;

import com.i.template.interceptor.LoginInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lewis
 * @type class
 * @description
 * @since 2024/7/25
 */
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {
//    private final LoginInterceptor loginInterceptor;
    private final StringRedisTemplate redisTemplate;
    @Value("f:/images/avatar")
    private String path;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 值越小 越先执行
        registry.addInterceptor(new LoginInterceptor(redisTemplate))
//                .addPathPatterns("/**")
                .excludePathPatterns("/user/login","/user/register","/images/**","/user/code/**").order(0);
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/avatar/**").addResourceLocations("file:" + path);
    }
}
